from rest_framework import serializers

from goods.models import SPUSpecification, SPU


class SPUSpecificationSerializer(serializers.ModelSerializer):

    # 嵌套返回指定的字段，返回的是模型类的__str__
    spu = serializers.StringRelatedField(read_only=True)
    # 返回关联spu的id值,根据模型类的表决定的
    spu_id = serializers.IntegerField()

    class Meta:
        model = SPUSpecification
        fields = "__all__"


class SPUSerializer(serializers.ModelSerializer):
    """商品序列化器"""
    class Meta:
        model = SPU
        fields = ('id', 'name')
